package com.tinyseed.hmxx.common.base;

/**
 * 版权所有 © Copyright 2019<br>
 *
 * @Description: <br>
 * @CreateDate: Created in 2019/8/8 23:18 <br>
 * @Author: Simon.Yu
 * @Modify:
 */
public class AjaxResult {

    public final static int SUCCESS = 20000;
    public final static int FAIL = 50000;

    private int code = SUCCESS;

    private String msg;

    private Object data;

    public AjaxResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;

        this.data = data;
//
//        if(data == null){
//            this.data = data;
//        }else{
//            if(data instanceof ORMModel){
//                this.data = ((ORMModel)data).toMap();
//            }else if(data instanceof Record){
//                this.data = ((Record)data).getColumns();
//            }else {
//                this.data = data;
//            }
//        }

    }

    public static AjaxResult succeed() {
        return new AjaxResult(SUCCESS, null, null);
    }

    public static AjaxResult succeed(String msg, Object data) {
        return new AjaxResult(SUCCESS, msg, data);
    }

    public static AjaxResult succeed(Object data) {
        return new AjaxResult(SUCCESS, null, data);
    }

    public static AjaxResult fail(String msg, Object data) {
        return new AjaxResult(FAIL, msg, data);
    }

    public static AjaxResult fail(String msg) {
        return new AjaxResult(FAIL, msg, null);
    }

    public static AjaxResult fail(int code) {
        return new AjaxResult(code, ErrorCodeManager.getMsg(code), null);
    }

    public boolean isSuccess() {
        return code == SUCCESS;
    }

    public void setSuccess(boolean success) {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
